package com.miyu.client1.test.AiApi;

import com.baidu.aip.speech.AipSpeech;
import com.baidu.aip.speech.TtsResponse;
import com.baidu.aip.util.Util;
import org.json.JSONObject;

import java.io.IOException;

public class speech {


        //文本转语音
        //设置APPID/AK/SK
        public static final String APP_ID = "24278995";
        public static final String API_KEY = "3PYSkIp6sjNHw3DygEzSqrVt";
        public static final String SECRET_KEY = "NT1aBvcAiU7Rpi1O3UuhBK3M7G1NCDXQ";
        public static void main(String[] args) {

            AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            // 调用接口
            TtsResponse res = client.synthesis("你好百度", "zh", 1, null);
            byte[] data = res.getData();
            JSONObject res1 = res.getResult();
            if (data != null) {
                try {
                    Util.writeBytesToFileSystem(data, "output.mp3");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (res1 != null) {
                System.out.println(res1.toString(2));
            }

        }


}
